/* 
 * File:   Image.cpp
 * Author: ungerma
 * 
 * Created on 15. August 2014, 16:15
 */

#include "SingleImage.h"
#include "Images.h"

SingleImage::SingleImage() {

}


SingleImage::SingleImage(Mat data, string filename, float groundTruth, 
        vector<ImageWindow> windows, float y) :
        data(data), filename(filename), groundTruth(groundTruth), 
        windows(windows), y(y) {
    
    
}

void SingleImage::releaseMatrix() {
    
    data.release();

}

Mat SingleImage::getData() {
    return data;
}

void SingleImage::setData(Mat data) {
    this->data = data;
}

string SingleImage::getFilename() {
    return filename;
}

void SingleImage::setFilename(string filename) {
    this->filename = filename;
}

float SingleImage::getGroundTruth() {
    return groundTruth;
}

void SingleImage::setGroundTruth(float groundTruth) {
    this->groundTruth = groundTruth;
}

vector<ImageWindow>* SingleImage::getWindows() {
    return &windows;
}

void SingleImage::addWindow(ImageWindow iw) {
    windows.push_back(iw);
}

void SingleImage::setWindows(vector<ImageWindow> windows) {
    this->windows = windows;
}

float SingleImage::getY() {
    return y;
}

void SingleImage::setY(float y) {
    this->y = y;
}


bool SingleImage::hasWindows() {
    return windows.size() > 0;
}

string SingleImage::getIDString() {
 
    /*
    ostringstream oss;
    oss << filename << " (original size)";
    return oss.str();
     */
    return "foo";
    
}

SingleImage* ImageWindow::getParent() {
    return parent;
}

ImageWindow::ImageWindow(Rect rectangle, int level) :
    rectangle(rectangle), pyramidLevel(level) {
    
    parent = NULL;
    
}

int ImageWindow::getPyramidLevel() {
    return pyramidLevel;
}

void ImageWindow::setPyramidLevel(int level) {
    this->pyramidLevel = level;
}

void ImageWindow::setParent(SingleImage* parent) {
    this->parent = parent;
}

Rect ImageWindow::getRectangle() {
    return rectangle;
}

void ImageWindow::setRectangle(Rect rectangle) {
    this->rectangle = rectangle;
}

Mat ImageWindow::getData() {

    if(parent == NULL) {
        return Mat();
    }
    
    Mat d = parent->getData();
    Mat ret = d;
    int level = pyramidLevel;
    
    while(level++ < 0) {
        resize(ret, ret, Size(d.size().width/Images::SCALE_SPACE_FACTOR,
                d.size().height/Images::SCALE_SPACE_FACTOR));
    }
    
    ret = ret(rectangle);
    return ret;

}

string ImageWindow::getIDString() {
 
    /*
    ostringstream oss;
    float scale = pow(Images::SCALE_SPACE_FACTOR, -pyramidLevel);
    int x = rectangle.x      / scale,
        y = rectangle.y      / scale,
        w = rectangle.width  / scale,
        h = rectangle.height / scale;
    
    string filename = "unknown";
    if(parent != NULL) {
        filename = parent->getFilename(); 
    }
    
    oss << filename << " (" <<
           x << ", " << y << ", " << w << ", " << h << ")"; 
    return oss.str();
     */
    return "foo";
    
}
